/* ************************************************************************************* 
 * CREATED BY:          GIAPCM
 * CREATED DATE:        10/02/2009
 * PROJECT:             MC ENT WEBSITE PROJECT
 * PURPOSE:             
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Telerik.Web.UI;
using Telerik.Web.UI.Editor.DialogControls;
using MCWEBSITE.ENTITY;
using MCWEBSITE.BUL;

public partial class Modules_WebsiteBackEnd_wucResourceUpload : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //Session["AdResource"] = null;
            this.GetNewsThumbParameter();
            if (rulImage.TargetFolder == "")
            {
                this.SetUploadParameters(lblResourceDir.Text);
            }
        }
    }

    //Get Thumb Parameter from Request Page
    protected void GetNewsThumbParameter()
    {
        lblResourceDir.Text = (string)Request.QueryString["ResourceDir"];
        lblNewsType.Text = (string)Request.QueryString["Act"];
    }

    //SET PARAMETERS FOR RAD UPLOAD
    public void SetUploadParameters(string ResourceDirectory)
    {
        rulImage.TargetFolder = ResourceDirectory;
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (rulImage.UploadedFiles.Count > 0)
        {
            UploadedFile FirstUploadedFile = rulImage.UploadedFiles[0];

            if (lblNewsType.Text.Trim() == "Ad")
            {
                Session["FILEUPLOAD"] = FirstUploadedFile.GetName();
            }
            else
            {
                DirectoryInfo ResourceDirectory = new DirectoryInfo(Server.MapPath(lblResourceDir.Text));
                if (ResourceDirectory.Exists)
                    foreach (FileInfo file in ResourceDirectory.GetFiles())
                        if (file.Name != FirstUploadedFile.GetName())
                            file.Delete();
            }
        }
    }
}
